package com.cps.frameauth.common.header;

import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.util.StrUtil;
import lombok.Data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 这里是描述
 *
 * @author 曹培胜
 * @date 2023-01-16 16:46
 */
@Data
public class HeadParams {
    /**
     * APIVersion
     */
    private String apiVersion;
    /**
     * 操作系统类型，
     */
    private String os;
    /**
     * 浏览器类型，
     */
    private String browser;
    /**
     * Web,API,Mobile,Tablet,Open-API,PC,App,miniApp
     */
    private String channel;
    /**
     * OSVersion
     */
    private String osVersion;
    /**
     * APP 端build 版本
     */
    private String buildVersion;
    /**
     * 设备号
     */
    private String deviceId;
    /**
     * JWT标准token
     */
    private String token;
    /**
     * CRM后台管理的token
     */
    private String crmToken;
    /**
     * 手机品牌
     */
    private String mobileBrand;
    /**
     * 手机品牌对应型号
     */
    private String mobileModel;
    /**
     * 网络环境
     */
    private String networkEnv;
    /**
     * 网络供应商
     */
    private String networkProvider;
    /**
     * app发行渠道
     */
    private String pkgDeliveryCode;
    /**
     * 对应语言，ISO标准
     */
    private String language;
    /**
     * 权限
     */
    private String authOperation;
    /**
     * 经度
     */
    private String longitude;
    /**
     * 纬度
     */
    private String latitude;
    /**
     * 媒体渠道
     */
    private String mediaChannel;
    /**
     * 对应产品， 后续， 一账通， 产品矩阵， 不同产品编号！， 比如 Hobby、Hohoy 等等， 这样的不同产品代号
     */
    private String product;
    /**
     * 安卓设备号
     */
    private String oaId;
    /**
     * 城市code
     */
    private String cityCode;
    /**
     * 城市名称
     */
    private String cityName;
    /**
     * 用户代理
     */
    private String userAgent;
    /**
     * 安卓ID
     */
    private String androidId;
    /**
     * 手机型号-iOS
     */
    private String model;
    /**
     * 发布入口场景类型
     */
    private String entryType;
    /**
     * ip
     */
    private String ip;
    /**
     * blackBox
     */
    private String blackBox;


    public static Map<String, String> buildExtraMap(HeadParams headParams) {
        Map<String, String> extraMap = MapBuilder.create(new HashMap<String, String>())
                .put("androidId", headParams.getAndroidId())
                .put("apiVersion", headParams.getApiVersion())
                .put("buildVersion", headParams.getBuildVersion())
                .put("cityCode", headParams.getCityCode())
                .put("deviceId", headParams.getDeviceId())
                .put("latitude", headParams.getLatitude())
                .put("longitude", headParams.getLongitude())
                .put("ip", headParams.getIp())
                .put("mobileBrand", headParams.getMobileBrand())
                .put("mobileModel", headParams.getMobileModel())
                .put("networkEnv", headParams.getNetworkEnv())
                .put("oaId", headParams.getOaId())
                .put("os", headParams.getOs())
                .put("osVersion", headParams.getOs())
                .put("pkgDeliveryCode", headParams.getPkgDeliveryCode())
                .put("token", headParams.getToken())
                .put("userAgent", headParams.getUserAgent())
                .build();
        List<String> notBlankValKeys = extraMap.keySet()
                .stream()
                .filter(key -> StrUtil.isNotEmpty(extraMap.get(key)))
                .collect(Collectors.toList());
        Map<String, String> notBlankExtraMap = new HashMap<>(notBlankValKeys.size());
        for (String key : notBlankValKeys) {
            notBlankExtraMap.put(key, extraMap.get(key));
        }
        return notBlankExtraMap;
    }
}
